package com.bys.controller;


import com.bys.po.User;
import com.bys.service.UserService;
import com.bys.util.PageResult;
import com.bys.util.R;
import com.bys.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/list")
    public List<User> list(){return userService.findAll();}
    @GetMapping("/findByPage")
    public com.bys.util.PageResult<User> findByPage(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize){
        return userService.findByPage(page,pageSize);
    }
    @PostMapping("/search")
    public PageResult<User> search(@RequestParam("page") Integer page,
                                   @RequestParam("pageSize") Integer pageSize,
                                   @RequestBody(required = false) UserVo userVo){
            return userService.search(page,pageSize,userVo);
        }
    @PostMapping("/save")
    public R save(@RequestBody User user){
        return userService.save(user) ? R.ok().message("添加成功！") : R.error().message("添加失败！");
    }
}

